<?php

class Html_Render_Div3
{
	public function render($group)
	{

		$l18n = Agis::getHelper('@l18n');
		
		$tag = $group -> getMeta('tag', 'div');
		
		$xhtml = array();

		
		$groupTitle = $group -> getMeta('title')?($group -> getNoTitle()?'':'<div class="form-group-title">' . $l18n -> _($group -> getMeta('title')) . '</div>'):'';
				
		$groupDesc= $group -> getMeta('desc')?($group -> getNoDesc()?'': '<div class="form-group-desc">' . $l18n -> _($group -> getMeta('desc')) . '</div>'):'';


		foreach ($group->getChildren() as $ele)
		{
			$label = $ele -> getMeta('label')?($ele -> getNoTitle()?'':'<div class="form-element-label">' . $l18n -> _($ele -> getMeta('label')) . '</div>'):'';
			$desc = $ele -> getMeta('desc')?($ele -> getNoTitle()?'':'<div class="form-element-desc">' . $l18n -> _($ele -> getMeta('desc')) . '</div>'):'';
			$html = $ele -> render();
			$xhtml[] = '<div class="form-element-wrapper">' . $label . '<div class="form-element-card-outer">' . $desc . $html . '</div>' . '</div>';
		}

		return sprintf('<%s %s>%s %s %s</div></%s>', $tag, $group -> flatAttrib(), $groupTitle, $groupDesc, implode(PHP_EOL, $xhtml), $tag);
	}

}
